/**
 * Created by jackliu on 17/01/04.
 */

var checkUtil = (function () {
    function checkUtil() {
    }

    //------------------------------------------------------------------
    // 提取number
    checkUtil.numberFromReq = function (req,name){
        return Number(req.query[name] || req.body[name] || '0');
    }

    //------------------------------------------------------------------
    // 提取string
    checkUtil.stringFromReq = function (req,name){
        return req.query[name] || req.body[name] || null;
    }

    //------------------------------------------------------------------
    // 提取 array
    checkUtil.arrayFromReq = function (req,name){
        var ret = null;
        var str = req.query[name] || req.body[name] || null;
        if (str == null || str.length < 2 || str[0]!='[' || str[str.length-1]!=']') {
            ret = null;
        }else{
            try{
                ret = JSON.parse(str);
            }catch(err){
                console.log(err);
            } finally {

            }

        }

        return ret;
    }


    //------------------------------------------------------------------

    return checkUtil;
})();
//------------------------------------------------------------------
module.exports = checkUtil;

